package com.tarena.lbs.marketing.web.consumer;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.marketing.web.service.CouponUserService;
import com.tarena.lbs.pojo.basic.event.LocationStoreEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class LocationStoresConsumer {
    @Autowired
    private CouponUserService couponUserService;
    //消费者consumer直接调用业务层,业务层处理的业务异常不会向外抛
    //系统异常 连接失败 解析失败 向外抛出 消费失败的,重复消费
    @StreamListener("location-stores-input")
    public void consume(LocationStoreEvent event){
        try{
            //业务代码
            couponUserService.autoSendCoupon(event);
        }catch (BusinessException e){
            log.error("业务异常",e);
        }
    }
}
